package com.liang.publics.util;

import android.annotation.SuppressLint;

import android.content.Context;

import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Handler;


import com.liang.publics.config.Const;
import com.liang.maogouyuyin.SplashActivity;

import java.util.List;


public class ApplicationUtil {



    @SuppressLint("QueryPermissionsNeeded")
    public static void ifPackageName(Context context,String packageNames) {



        try {

            if("vivo".equals(SplashActivity.mymanufacturer) && Const.ifPackageNameCount<2) {
//            if(true) {


                if(SharedPreferencesUtil.getStatus(SharedPreferencesUtil.IF_AD)) {
                    Const.ifPackageNameCount++;
                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {


//                            Toast.makeText(context, "ifPackageName！", Toast.LENGTH_SHORT).show();
                            PackageManager packageManager = context.getPackageManager();
                            List<ApplicationInfo> applications = packageManager.getInstalledApplications(PackageManager.GET_META_DATA);


                            for (ApplicationInfo applicationInfo : applications) {
                                String packageName = applicationInfo.packageName;
                                //            packageName= "com.vivo.autotest.screen_record";
                                if (packageName != null) {
                                    if (packageName.indexOf(packageNames) > -1) {
//                                    if (true) {

                                        SharedPreferencesUtil.saveStatus(SharedPreferencesUtil.IF_AD, false);

                                        break;
                                    }
                                }

                            }

                        }
                    }, 5000);
                }
            }


        }catch (Exception e){
            e.printStackTrace();
        }finally {

        }

    }




}
